const gulp = require('gulp')
const autoprefixer = require('gulp-autoprefixer')
const sass = require('gulp-sass')(require('sass'))

const args = process.argv.slice(2)
const sassConfig = {
  outputStyle: args.includes('build') ? 'compressed' : 'expanded',
  charset: false
}

exports.build = function() {
  return gulp.src('src/scss/index.scss')
    .pipe(sass(sassConfig).on('error', sass.logError))
    .pipe(autoprefixer({ cascade: false }))
    .pipe(gulp.dest('dist'))
}

exports.watch = function() {
  gulp.watch('src/scss/**/*', { delay: 500 }, exports.build)
}
